<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue@2.7.14/dist/vue.js"></script>
</head>

<body>
    <div id="app">
        <span>全选:</span>
        <input type="checkbox" v-model="isAll" />
        <button @click="change()">反选</button>
        <ul>
            <li v-for="item in arr">
                <input type="checkbox" v-model="item.checked" />
                <span>{{item.name}}</span>
            </li>
        </ul>
    </div>
    <script>
        const app = new Vue({
            el: '#app',
            data: {
                arr: [{
                    name: "猪八戒",
                    checked: false
                }, {
                    name: "孙悟空",
                    checked: false
                }, {
                    name: "唐僧",
                    checked: false
                }, {
                    name: "白龙马",
                    checked: false
                }]
            },
            methods: {
                change() {
                    this.arr.map(item => item.checked = !item.checked);
                }
            },
            computed: {
                isAll: {
                    get() {
                        return this.arr.every(item => item.checked)
                    },
                    set(flag) {
                        return this.arr.forEach(item => item.checked = flag);
                    }
                }

            }
        })
    </script>
</body>

</html>